<!DOCTYPE html>
<html  lang="zh" xmlns:th="http://www.thymeleaf.org">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta name="viewport" content="width=device-width"/>
<meta content="yes" name="apple-mobile-web-app-capable">
<meta name="viewport" content="width=device-width,height=device-height,inital-scale=1.0,maximum-scale=1.0,user-scalable=no;">
<head th:include="include :: header"><!--<title>扫码发货</title>--></head>
<link th:href="@{/css/plugins/dropzone/basic.css}" rel="stylesheet"/>
<link th:href="@{/css/plugins/dropzone/dropzone.css}" rel="stylesheet"/>
<link th:href="@{/css/style.css?v=4.1.0}" rel="stylesheet">
<style>
    .textarea_div{
        width: 100%;
        height: 130px;
        border: 1px solid;
        padding: 2px 2px 2px 2px;
        line-height: inherit;
        overflow: auto;
        margin: 0;
        font: inherit;
        color: inherit;
        -webkit-appearance: textarea;
        background-color: white;
        -webkit-rtl-ordering: logical;
        flex-direction: column;
        cursor: text;
        white-space: pre-wrap;
        word-wrap: break-word;
        text-rendering: auto;
        letter-spacing: normal;
        word-spacing: normal;
        text-transform: none;
        text-indent: 0;
        text-shadow: none;
        display: inline-block;
        text-align: start;}

</style>
<body class="white-bg">
<div class="ibox-content">
    <form action="" method="post" class="form-horizontal m" id="form-sweepCodeLocation" >
        <input id="id" name="id"   type="hidden">
        <div class="form-horizontal m">

            <div class="form-group">
                <div class="">
                    <button type="submit" class="btn btn-primary" data-loading-text="Loading..." style="margin-left: 15px">confirm</button><!--  onclick="upload()" -->
                    <button onclick="$.modal.close()" class="btn btn-danger" type="button">close</button>
                </div>
            </div>
            <div class="form-group">
                <div class="col-sm-8">
                    <input class="form-control" placeholder="Please scan the shelf number"  type="text" name="smLocationId" id="smLocationId">
                </div>
            </div>
            <div class="form-group">
                <div class="col-sm-8">
                <select class="form-control" id="locationId" name="locationId" >
                    <option th:each="location : ${locationList}" th:text="${location.locationName}"
                            th:value="${location.locationId}"></option>
                </select>
                </div>
            </div>
            <!--<textarea style="width: 100%;height: 130px;border: 1px solid;padding:2px 2px 2px 2px;" class="stockIds"></textarea>-->
            <div class="textarea_div stockIds" contenteditable="true"></div>
            <span>
                <font style="color: red">*</font>Multi - barcode batch shipment please use
                <font style="color: red"> comma </font>
                separated(The scan format of the gun can be identified after special processing,It is normal for line breaks to change commas after confirmation)
            </span><br>
            <div class="notExistOrder">
                <font style="color: red">*</font>The red order number indicates that the order does not exist in this state or is on the shelf
            </div>
            <div class="notExistOrder">
                <font style="color: red">*</font>Priority scan code shelf number is larger than the selection box
            </div>
            <span class="orderFlag" style="display: none" th:text="${flag}"></span>

        </div>

    </form>

</div>

<div th:include="include::footer"></div>
<script th:src="@{/ajax/libs/jquery-migrate/jQuery.print.min.js}"></script>
<script th:src="@{/js/plugins/dropzone/dropzone.js}"></script>
<script th:src="@{/js/plugins/layer/layer.min.js}"></script>
<script th:src="@{/ajax/libs/select/select2.js}"></script>
<script type="text/javascript">

    $(function () {
        $(".textarea_div").focus();
    })

    var prefix = ctx + "module/location"
    $("#form-sweepCodeLocation").validate({
        rules:{
            smLocationId:{
                remote: {
                    url: prefix + "/checkLocationIdUnique",
                    type: "post",
                    dataType: "json",
                    data: {
                        "smLocationId" : function() {
                            return $.trim($("#smLocationId").val());
                        }
                    },
                    dataFilter: function(data, type) {
                        if (data == "1") return true;
                        else return false;
                    }
                }
            },
        },
        submitHandler: function(form) {
            var ids_str = $('.stockIds').text();//文本框的条码id内容
            var ids_arr = trimNull(ids_str.split(/[\r|\n|\\s|,|，]/));//条码id数组
            var  url = prefix + "/sweepCodeLocation"

            console.log(ids_arr)

            if(ids_str.trim()==""){
                $.modal.alertWarning('Please add barcode ID！');
                return false;
            }else {
                var locationIds =$("#locationId").val();
                if (objIsNull($("#smLocationId").val())){
                    locationIds = $("#smLocationId").val()
                }

                $.ajax({
                    cache : true,
                    type : "POST",
                    url : url,
                    data : {
                        smIds:ids_arr,
                        locationIds:locationIds,
                        // sign:'10702',
                    },
                    async : true,
                    error : function(request) {
                        $.modal.alertError("The system is busy, please refresh and try again！");
                    },
                    success : function(data) {
                        var returnTextarea = [];//返回的订单数据
                        var notExistOrder = '';
                        if(data.length!=0) {//表示有不存在的订单，提示不存在的订单为红色
                            for (var j = 0;j<ids_arr.length;j++){//在返回的不存在订单中循环对比录入订单，不存在则变红色
                                if(data.indexOf(ids_arr[j])>-1){
                                    returnTextarea += '<span style="color: red">'+ids_arr[j]+'</span>';
                                }else {
                                    returnTextarea += ids_arr[j];
                                }

                                if(j!=ids_arr.length-1){
                                    returnTextarea += ',';
                                }
                            }
                        }else {//发货成功
                            $.modal.msgReload("hit the shelves successfully,the data is being refreshed. Please wait……", modal_status.SUCCESS)
                        }
                        $('.stockIds').html(returnTextarea);
                    }
                });
            }

        }
    });

</script>
</body>
</html>